package com.ruoyi.eims.purchase.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eims.purchase.domain.PurchaseOrderDetails;
import com.ruoyi.eims.purchase.service.IPurchaseOrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购订单明细Controller
 * 
 * @author hp
 * @date 2023-02-04
 */
@RestController
@RequestMapping("/details")
public class PurchaseOrderDetailsController extends BaseController
{
    @Autowired
    private IPurchaseOrderDetailsService purchaseOrderDetailsService;

    /**
     * 查询采购订单明细列表
     */
    @RequiresPermissions("purchase:details:list")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseOrderDetails purchaseOrderDetails)
    {
        startPage();
        List<PurchaseOrderDetails> list = purchaseOrderDetailsService.selectPurchaseOrderDetailsList(purchaseOrderDetails);
        return getDataTable(list);
    }

    /**
     * 导出采购订单明细列表
     */
    @RequiresPermissions("purchase:details:export")
    @Log(title = "采购订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseOrderDetails purchaseOrderDetails)
    {
        List<PurchaseOrderDetails> list = purchaseOrderDetailsService.selectPurchaseOrderDetailsList(purchaseOrderDetails);
        ExcelUtil<PurchaseOrderDetails> util = new ExcelUtil<PurchaseOrderDetails>(PurchaseOrderDetails.class);
        util.exportExcel(response, list, "采购订单明细数据");
    }

    /**
     * 获取采购订单明细详细信息
     */
    @RequiresPermissions("purchase:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchaseOrderDetailsService.selectPurchaseOrderDetailsById(id));
    }

    /**
     * 新增采购订单明细
     */
    @RequiresPermissions("purchase:details:add")
    @Log(title = "采购订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseOrderDetails purchaseOrderDetails)
    {
        return toAjax(purchaseOrderDetailsService.insertPurchaseOrderDetails(purchaseOrderDetails));
    }

    /**
     * 修改采购订单明细
     */
    @RequiresPermissions("purchase:details:edit")
    @Log(title = "采购订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseOrderDetails purchaseOrderDetails)
    {
        return toAjax(purchaseOrderDetailsService.updatePurchaseOrderDetails(purchaseOrderDetails));
    }

    /**
     * 删除采购订单明细
     */
    @RequiresPermissions("purchase:details:remove")
    @Log(title = "采购订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchaseOrderDetailsService.deletePurchaseOrderDetailsByIds(ids));
    }
}
